<!-- 编辑弹窗 -->
<template>
    <div class="ele-body">
      <el-card>
        <!-- 搜索表单 -->
        <costmanagerDetailSearch @search="reload"  />
      </el-card>
      <el-card>
        <ele-pro-table ref="table"  row-key="id" :columns="warehouseItemColumns"  :datasource="datasource"  :need-page="true"  show-summary :summary-method="getSummaries" :cell-style="cellStyle" :height="tableHeight" :full-height="tableFullHeight">
         
        </ele-pro-table>
      </el-card>
    </div>
  </template>
  <script>

  //初始化对像
  import { removePageTab } from '@/utils/page-tab-util';
  import costmanagerDetailSearch from '../components/costmanager-detail-search.vue';
  import { QueryCostmanagerDetailSummaryViewByCondition } from '@/api/statistics';


  export default {
    name: 'CostManagerDetail',
    props: {
      // 弹窗是否打开
      visible: Boolean,
      // 修改回显的数据
      data: Object,
    },
    components:{costmanagerDetailSearch},
    data() {
      return {
        // 表单数据
        form: {},
        fixedHeight:true,
        // 提交状态
        loading: false,
        // 是否是修改
        isUpdate: false,
        // 表格列配置
        warehouseItemColumns: [
          {columnKey: 'index', type: 'index', width: 50, align: 'center', showOverflowTooltip: true, fixed: 'left', label:'序号',},
          {prop: 'costTypeDesc', label: '费用类型',width: 150,  showOverflowTooltip: true,align: 'center', },
          {prop: 'bankAccountDesc', label: '支出账户', showOverflowTooltip: true,align: 'center' },
          {prop: 'operatorName', label: '经办人', showOverflowTooltip: true, align: 'center'},
          {prop: 'amount', label: '金额', showOverflowTooltip: true, align: 'center',sortable:'amount'},
          {
            prop: 'peddingDate', label: '发生日期', width: 150, showOverflowTooltip: true, align: 'center',sortable: 'peddingDate',
            formatter: (row, column, cellValue) => {return this.$util.toDateString(cellValue,"YYYY-MM-DD");}
          },
        ],
        amountTotal:0,
      };
    },
    computed: {
      // 表格高度
      tableHeight() {
        var fh = this.fixedHeight ? 'calc(100vh - 450px)' : void 0;
        return fh;
      },
      // 表格全屏时高度
      tableFullHeight() {
        var fh =  this.fixedHeight ? 'calc(100vh - 350px)' : null;
        return fh;
      },
    },
    created(){
      this.costTypeId = this.$route.query.costTypeId;
    },
    methods: {

      /* 表格数据源 */
      async datasource(params) {

        params.where.pageindex = params.page;
        params.where.pagesize = params.limit;

        //添加排序
        if(params.order.order == null || params.order.order == undefined){
          params.where.orderBys = [{ sort: "createDate", order: 1, }];
        }else{
          params.where.orderBys = [];
          params.where.orderBys.push({sort:params.sorter.column.sortable,order:params.order.order=='asc'?0:1});
        }

        if(!params.where.conditions)params.where.conditions = {};

        if(this.costTypeId){
          params.where.conditions.costTypeId =  this.costTypeId;
        }

        let data = await QueryCostmanagerDetailSummaryViewByCondition(params.where);
        this. amountTotal=data.amountTotal;
        
        this.$nextTick(() => {
          this.$refs.table.doLayout();
        });

        return {
            list:data.costmanagerDetailView,
            count:data.totalrecords,
        };
      },

      /* 更新visible */
      updateVisible(value) {
        //更新父组件中的visible的值
        this.$emit('update:visible', value);
        //更新文件列表对像
      },

      /* 刷新表格 */
      reload(where) {
        if(this.$refs.table){
          this.$refs.table.reload({ where: where });
        }
      },

      //单击单号
      clickbillNo(row){

        // 采购订单
        removePageTab({ key: '/businesshandling/saleoutmanger' });
        this.$nextTick(() => {
          this.$router.push({path: '/businesshandling/saleoutmanger', query: { "orderNo": row.outOrderNo } });
        });
      },
      /* 合计 */
      getSummaries(param){
        const sums = [];
        sums[0] = '合计' ;
        const { columns, data } = param;
        columns.forEach((column, index) => {
          if(index ==4){
            sums[index] =  Number(this.amountTotal).toFixed(4);
          }
        });

        this.$nextTick(() => {
          this.$refs.table.doLayout();
        });
        return sums;
      },
  
      /* 样式 */
      cellStyle(param){
        const { row, column, rowIndex, columnIndex } = param;
        if(columnIndex==4){
          return{
            color:''
          }
        }
      },
  },
    
    /* 监听visible属性变化 */
    watch: {
      visible(visible) {
        if (visible) {
          //赋值this.form
          this.form = this.data;
          this.isUpdate = this.data.id !=null && this.data.id !=undefined;

          this.reload();
        } 
      }
    }
  };
  </script>
     <style lang="scss" scoped>
     /*总计字体颜色
     ::v-deep .el-table__footer-wrapper tbody td {
       color: var(--color-primary);
       cursor: pointer;
     }*/
   </style>